/**
 * 
 */
package com.bbcare.comm;

import java.math.BigDecimal;

/*
 * @name:         BigDecimalUtil.java
 * @author:       tao
 * @createTime:   2018年7月4日
 * @description:  精度计算操作类
 * @modify:
 * 
 */
public class BigDecimalUtil {
	/**加*/
	public static double add(double before,double after){
	    BigDecimal beforeDecimal = new BigDecimal(Double.toString(before));
	    BigDecimal afterDecimal = new BigDecimal(Double.toString(after));
	    return beforeDecimal.add(afterDecimal).doubleValue();
	}
	
	/**减*/
	public static double subtract(double before,double after){
	    BigDecimal beforeDecimal = new BigDecimal(Double.toString(before));
	    BigDecimal afterDecimal = new BigDecimal(Double.toString(after));
	    return beforeDecimal.subtract(afterDecimal).doubleValue();
	}
	
	/**乘*/
	public static double multiply(double before,double after){
	    BigDecimal beforeDecimal = new BigDecimal(Double.toString(before));
	    BigDecimal afterDecimal = new BigDecimal(Double.toString(after));
	    return beforeDecimal.multiply(afterDecimal).doubleValue();
	}
	
	/**除*/
	public static double divide(double before,double after){
	    BigDecimal beforeDecimal = new BigDecimal(Double.toString(before));
	    BigDecimal afterDecimal = new BigDecimal(Double.toString(after));
	    
	    return beforeDecimal.divide(afterDecimal,2,BigDecimal.ROUND_HALF_DOWN).doubleValue();
	}
}
